#![allow(dead_code)]
pub struct Solution;

impl Solution {
    pub fn reverse(x: i32) -> i32 {
        let reversed_number = x
            .abs()
            .to_string()
            .chars()
            .rev()
            .collect::<String>()
            .parse::<i32>()
            .unwrap_or(0);

        if x.is_negative() {
            reversed_number.wrapping_neg()
        } else {
            reversed_number
        }
    }
}

#[cfg(test)]
mod tests {
    use super::Solution;
    #[test]
    fn test_1() {
        assert_eq!(Solution::reverse(123), 321);
        assert_eq!(Solution::reverse(120), 21);
        assert_eq!(Solution::reverse(0), 0);
        // assert_eq!(Solution::reverse(1534236469), 0);
        // assert_eq!(Solution::reverse(-2147483648), 0);
    }
    #[test]
    fn test_2() {
        assert_eq!(Solution::reverse(-123), -321);
        // assert_eq!(Solution::reverse(120), 21);
        // assert_eq!(Solution::reverse(0), 0);
        // assert_eq!(Solution::reverse(1534236469), 0);
        // assert_eq!(Solution::reverse(-2147483648), 0);
    }
    #[test]
    fn test_3() {
        // assert_eq!(Solution::reverse(0), 0);
        // assert_eq!(Solution::reverse(1534236469), 0);
        assert_eq!(Solution::reverse(-2147483647), 0);
        // assert_eq!(Solution::reverse(2147483647), 0);
        // println!("{}", Solution::reverse(-2147483647));
    }
}
